package 笔试.aa.b;

import org.junit.Test;

public class AA {
    @Test
    public void test() {
        System.out.println(minM(10,10));
    }
    public long minM (int n, int k) {
        long x = 1;
        int c=0;
        while(true){
            c += f(x, k);
            if(c>=n)return x;

            x++;
        }
    }

    private int f(long x, int k) {
        String s = Integer.toString(Math.toIntExact(x), k);
        char[] c = s.toCharArray();
        int gs=0;
        for (char c1 : c) {
            if(c1=='1')gs++;
        }
        return gs;
    }
}
